
const queryFormRules = {
	date: [
	    {required: true, message: '请输入月份范围', trigger: 'blur'}
	]
	};
const payRules = {
	date: [
	    {required: true, message: '请输入月份范围', trigger: 'blur'}
	],
	deptid: [
	    {required: true, message: '请输入部门', trigger: 'blur'}
	],
	paytype: [
	    {required: true, message: '请输入付款方式', trigger: 'blur'}
	],
	companyid: [
		{required: true, message: '请输入收款单位', trigger: 'blur'}
	],
	bankno: [
		{required: true, message: '请输入账号', trigger: 'blur'}
	],
	bankname: [
		{required: true, message: '请输入开户银行', trigger: 'blur'}
	],
	amount: [
		{required: true, message: '请输入付款金额', trigger: 'blur'}
	],
	content: [
		{required: true, message: '请输入付款事由', trigger: 'blur'}
	],
	paytype: [
		{required: true, message: '请输入付款方式', trigger: 'blur'}
	],
	agentid: [
        {required: true, message: '请输入经办人', trigger: 'blur'}
    ],
	approverid: [
		{required: true, message: '请输入审批人', trigger: 'blur'}
	],
	cashierid: [
		{required: true, message: '请输入出纳', trigger: 'blur'}
	],
	bookkeeperid: [
		{required: true, message: '请输入会计', trigger: 'blur'}
	]
};
			
let app = new Vue({
    el: "#app",
    data() {
        return {
        	leftbar_show:true,
			// 添加、编辑标识
			tableHeight:window.innerHeight - 180,
			queryForm:{
				userid: localStorage.getItem('USERID'),
                yourname: "",
				status:[],
				date:[],
				pageNo:1, // 当前页码
				pagesize:100 ,// 每页记录数
				pagesizes:[10,20,50,100,500]
				
			},
			pagetotal:0,
			pickerOptions: {
			  shortcuts: [{
				text: '最近一周',
				onClick(picker) {
				  const end = new Date()
				  const start = new Date()
				  start.setTime(start.getTime() - 3600 * 1000 * 24 * 7)
				  picker.$emit('pick', [start, end])
				}
			  }, {
				text: '最近一个月',
				onClick(picker) {
				  const end = new Date();
				  const start = new Date();
				  start.setTime(start.getTime() - 3600 * 1000 * 24 * 30);
				  picker.$emit('pick', [start, end]);
				}
			  }, {
				text: '最近三个月',
				onClick(picker) {
				  const end = new Date();
				  const start = new Date();
				  start.setTime(start.getTime() - 3600 * 1000 * 24 * 90);
				  picker.$emit('pick', [start, end]);
				}
			  }]
			},
			
			 TheNumber: [{
			            number: '1',
			            name: '陈益国',
			            bumen: '运营部',
						month: '22',
						real: '22',
						day1: '√',
						day2: '√',
						day3: '√',
						day4: '√',
						day5: '√',
						day6: '休',
						day7: '休'
			          }, {
			            number: '2',
			            name: '王倩',
			            bumen: '会计部',
						month: '21',
						real: '21',
						day1: '√',
						day2: '√',
						day3: '√',
						day4: '√',
						day5: '√',
						day6: '休',
						day7: '休'
			          }, {
			            number: '3',
			            name: '季洁',
			            bumen: '运营部',
						month: '22',
						real: '22',
						sholiday: '2.5',
						illholiday: '2.5',
						day1: '√',
						day2: '√',
						day3: '√',
						day4: '√',
						day5: '√',
						day6: '休',
						day7: '休'
			          }, {
			            number: '4',
			            name: '程闪闪',
			            bumen: '运营部',
						month: '22',
						real: '20',
						sholiday: '2',
						day3: '√',
						day4: '√',
						day5: '√',
						day6: '休',
						day7: '休'
			          }],
					  
			dialogimportFormVisible :false,
			importForm: {
				src:"工商",
				assignetype:"手动",
				deptid:parseInt(localStorage.getItem('DEPTID'))
			},
			form: {
					  name: '',
					  region: '',
					  date1: ''
					},										
			uploadurl:axios.defaults.baseURL + "api/payform/annex/upload/",
			headers: {
				Token: localStorage.getItem('TOKEN'),
				UserID: localStorage.getItem('USERID')
			},
			userid:	localStorage.getItem('USERID'),
			// 多选
			multipleSelection:[],
			pagedata:[],  // 当前页结果集
			loaded:false,
			// 所有部门
			depts:[],
			// 所有用户
			allusers:[],
			users:['是','否'],
			paytypes:['支付宝','微信','对公','现金'],
			statuses:['在职','离职'],
			companys: ['1', '2','3'],
			workpalces: ['公司','家'],
			onlines: ['是','否'],
			writenames: ['是','否'],
			bumens:['市场部','IT部','会计部','人事部','财务部'],
			action:" ",
			outerVisible: false,
			innerVisible: false,
			dialogimportFormVisible: false,
			imgdialogVisible:false,
			imgdialogImageUrl:''
        }
    },
	methods: {
		// 显示侧边栏
		showLeftBar() {
			if (this.leftbar_show) {
				this.leftbar_show = false
			} else {
				this.leftbar_show = true
			}
		},
		start(){
			this.queryForm.pageNo = 1
			this.query()
		},
		 onSubmit() {
		        console.log('submit!');
		      },
			  
		// 查询
		async query() {
			// 显示加载框
			const loading = this.$loading(LOAD_STYLE);
			try {
				let res = await axios.post('api/payform/query', this.queryForm);
				if (res.code === 200) {
					this.pagedata = res.data;
					this.pagetotal = res.total;
					this.$message.success(res.message);
				}else {
					this.$message.error(res.message);
				}
			}catch (e) {
				this.$message.error('查询请求出错！', e.message);
			}
			
			// 关闭加载框
			loading.close();
		},
		beforeAvatarUpload(file) {
			// 显示加载框
			this.importloading = this.$loading(LOAD_STYLE);
			const isLt5M = file.size / 1024 / 1024 < 20;
			console.log(this.uploadurl + this.importForm.src + ',' + this.importForm.assignetype+ ',' + this.importForm.deptid)
			if (!isLt5M) {
				this.$message.error('上传文件大小不能超过 20MB!');
				// 关闭加载框
				this.importloading.close();
				return false;
			}
			return true;
		},				
		handleAvatarSuccess(res, file, filelist) {
		// 导入完成
			try {
				if (res.code === 200) {
					this.$message.success(res.message);
				}else {
					this.$message.error(res.message);
				}
			}catch (e) {
				this.$message.error('请求出错！', e.message);
			}
			// 关闭加载框
			this.importloading.close();
		},

		// 设定表格当前页
		handleCurrentPageChange (selectedPageNo) {
		  this.queryForm.pageNo = selectedPageNo
		  // 加载数据页
		  this.query()
		},

		// 取得所有用户列表
		async getAllUser() {
			// 显示加载框
			const loading = this.$loading(LOAD_STYLE);
			try {
				let res = await axios.get('api/user/all');
				if (res.code === 200) {
					this.allusers = res.data;
				} else {
					this.$message.error(res.message);
				}
			} catch (e) {
				this.$message.error('取得所有用户列表请求出错！', e.message);
			}
			// 关闭加载框
			loading.close();
		},
	},
	async mounted() {
		// 自动调整表格高度
		window.onresize = () => {
		  return (() => {
			this.tableHeight = window.innerHeight - 180
		  })()
		}
	}
});	